/* Finds the largest and smallest elements in an array */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
void max_min(int *a, int n, int *max, int *min);
void init_array(int *, int n);
int main(void)
{
    int b[N], i, big, small;
    init_array(b, N);
    max_min(b, N, &big, &small);
    printf("Largest: %d\n", big);
    printf("Smallest: %d\n", small);
    return 0;
}
void max_min(int *a, int n, int *max, int *min) {
    *max = *min = *a;
    for (int *p = a + 1; p < a + n; p++) {
        if (*p > *max)
            *max = *p;
        else if (*p < *min)
            *min = *p;
    }
}
void init_array(int *a, int n) {
    srand((unsigned) time(NULL));
    for (int *p = a; p < a + n; p++)
        *p = rand() % 100;
    printf("Random numbers:");
    for (int *p = a; p < a + n; p++)
        printf(" %d", *p);
    printf("\n");
}